home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib2to3 / fixes / fix_apply.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.9 KB  |  48 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Fixer for apply().
  5.  
  6. This converts apply(func, v, k) into (func)(*v, **k).'''
  7. from  import pytree
  8. from pgen2 import token
  9. from  import fixer_base
  10. from fixer_util import Call, Comma, parenthesize
  11.  
  12. class FixApply(fixer_base.BaseFix):
  13.     PATTERN = "\n    power< 'apply'\n        trailer<\n            '('\n            arglist<\n                (not argument<NAME '=' any>) func=any ','\n                (not argument<NAME '=' any>) args=any [','\n                (not argument<NAME '=' any>) kwds=any] [',']\n            >\n            ')'\n        >\n    >\n    "
  14.     
  15.     def transform(self, node, results):
  16.         syms = self.syms
  17.         if not results:
  18.             raise AssertionError
  19.         func = results['func']
  20.         args = results['args']
  21.         kwds = results.get('kwds')
  22.         prefix = node.get_prefix()
  23.         func = func.clone()
  24.         if func.type not in (token.NAME, syms.atom):
  25.             if func.type != syms.power or func.children[-2].type == token.DOUBLESTAR:
  26.                 func = parenthesize(func)
  27.             
  28.         func.set_prefix('')
  29.         args = args.clone()
  30.         args.set_prefix('')
  31.         if kwds is not None:
  32.             kwds = kwds.clone()
  33.             kwds.set_prefix('')
  34.         
  35.         l_newargs = [
  36.             pytree.Leaf(token.STAR, '*'),
  37.             args]
  38.         if kwds is not None:
  39.             l_newargs.extend([
  40.                 Comma(),
  41.                 pytree.Leaf(token.DOUBLESTAR, '**'),
  42.                 kwds])
  43.             l_newargs[-2].set_prefix(' ')
  44.         
  45.         return Call(func, l_newargs, prefix = prefix)
  46.  
  47.  
  48.